<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/22 0022
 * Time: 10:10
 */

namespace app\admin\controller;


use think\Controller;
use think\Config;
use think\Loader;
use think\Db;
use think\Session;

class IndexController extends BaseController
{
    //主页
    public function index(){
        return $this->fetch("index");
    }
    //ifrm的内容
    public function welcome(){

// 系统
        $systemInfo['os'] = PHP_OS;
//ThinkPHP 版本
        $systemInfo['ThinkPHP'] = THINK_VERSION;
// PHP版本
        $systemInfo['phpversion'] = PHP_VERSION;
// 最大上传文件大小
        $systemInfo['maxuploadfile'] = ini_get('upload_max_filesize');
// 脚本运行占用最大内存
        $systemInfo['memorylimit'] = get_cfg_var("memory_limit") ? get_cfg_var("memory_limit") : '-';
//当前的IP
        $systemInfo['REMOTE_ADDR']=$_SERVER['REMOTE_ADDR'];
// 数据统计
        $data["goods_cate"]=Db::name("goods_cate")->count();
        $data["user"]=Db::name("user")->count();
        $data["admin"]=Db::name("admin")->count();
        $data["auth_role"]=Db::name("auth_role")->count();

//当前日期
        $ymd=date("Y-m-d");
        $this->assign("ymd",$ymd);
        $this->assign("systemInfo",$systemInfo);
        $this->assign("data",$data);
        return $this->fetch('welcome');
    }
    
    public function get_info(){
        $admin_id=Session::get("admin_id");
        $find=Db::name("admin")->where(["id"=>$admin_id])->find();
        if (empty($admin_id)){
            return json(["code"=>0,"msg"=>"不存在该用户的"]);
        }
        if (request()->isAjax()){
            $list=request()->post();
            /*if ($find["password"]==$list["password"]){
                $list["password"]=$find["password"];
            }else{
                $list["password"]=pswCrypt($list["password"]);
            }*/
            $result=Db::name("admin")->where(["id"=>$list["id"]])->update($list);
            if ($result){
                return json(["code"=>1,"msg"=>"编辑成功"]);
            }else{
                return json(["code"=>0,"msg"=>"编辑失败"]);
            }
        }
        $this->assign("find",$find);
        return $this->fetch("get_info");

    }


}